Ext.namespace("Ext.milan.pagejs.page_modulemanage");
Ext.milan.pagejs.page_modulemanage.userWin = null;

Ext.milan.pagejs.page_modulemanage.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.page_modulemanage.docOnReadyCallback = function() {

	Milan.ajaxutility.updateContentUseAjax("post","module/tree.do?appid="+$('appid').value,"module_left_data");
	//Milan.ajaxutility.updateContentUseAjax("post","directory/subDir.do?typeId=-1", "knowledgeTypeFrame_rightFrame");
};


Ext.milan.pagejs.page_modulemanage.addSame = function(formId)
{
	var formEle = $(formId);
	if(formEle.mdParentId.value=="-1") 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"不能新建根目录!");
		return false;
	}
	if(formEle.mdParentId.value != "-1" && formEle.module_pid.value != '') 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"只能选择一级模块!");
		return false;
	}
    var url = "module/create.do?appid="+formEle.module_appid.value;
	Ext.milan.pagejs.page_modulemanage.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:650
	});
}

Ext.milan.pagejs.page_modulemanage.modifySelfType = function(formId)
{	
	var formEle = $(formId);
	if(formEle.mdParentId.value=="") 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择模块!");
		return ;
	}
    var url = "module/edit.do?mdid="+formEle.mdParentId.value;
	Ext.milan.pagejs.page_modulemanage.userWin = Milan.commonutils.createModelPop({
		title:"编辑", 
		url:url,
		width:650
	});
}

Ext.milan.pagejs.page_modulemanage._formCheck = function(frm) {
	function focusElement(el) {
		if(el.focus)
			el.focus();
	};
	if(frm.name.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "名称 不能为空！");
		return false;
	}
	if(frm.sortno.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "序号 不能为空！");
		return false;
	}
	return true;
};

Ext.milan.pagejs.page_modulemanage._saveInfo = function(formId) {
	if(!Ext.milan.pagejs.page_modulemanage._formCheck($(formId)))
		return;
		
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_modulemanage.closeWin();
			Ext.milan.pagejs.page_modulemanage.refreshTree($('appid').value);
		}
	});
};

Ext.milan.pagejs.page_modulemanage.deleteSelfType = function(formId) {
	var formEle = $(formId);
	if(formEle.mdParentId.value=="") 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择模块!");
		return ;
	}
	var url = "module/delete.do?mdid=" + formEle.mdParentId.value;
	new Milan.widget.ConfirmDialog("确认信息", "确认要删除该信息吗？", {
		confirmCallback: function() {
			Milan.ajaxutility.formSubmit({
				url: url,
				method: 'post',
				success: function(response, option)
				{
					Ext.milan.pagejs.page_modulemanage.refreshTree($('appid').value);
				}
			});
		}
	});	
};

Ext.milan.pagejs.page_modulemanage.addSubType = function(formId)
{
	var formEle = $(formId);
	var formEle = $(formId);
	if(formEle.mdParentId.value=="") 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择模块!");
		return ;
	}
	if(formEle.mdParentId.value=="-1") 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"不能选择根目录!");
		return false;
	}
	if(formEle.mdParentId.value != "-1" && formEle.module_pid.value != '') 
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"只能选择一级模块!");
		return false;
	}
    var url = "moduleData/list.do?mdpid="+formEle.module_ParentId.value+"&appid="+formEle.module_appid.value;
	Ext.milan.pagejs.page_modulemanage.userWin = Milan.commonutils.createModelPop({
		title:"功能库", 
		url:url,
		width:650
	});
}

Ext.milan.pagejs.page_modulemanage.deleteSubType = function(formId) {
	var formEle = $(formId);
	if((Ext.milan.pagejs.page_modulemanage.selectCount(formEle)== 0))
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择要删除的功能！");
		return false;
	}
	else
	{
		formEle.action = "module/bathDelete.do";
		new Milan.widget.ConfirmDialog("确认信息", "确认要删除该功能吗？", {
			confirmCallback: function() {
				Milan.ajaxutility.formSubmit({
					form : formEle.id,
					method: 'post',
					success: function(response, option)
					{
						Ext.milan.pagejs.page_modulemanage.refreshTree($('appid').value);
					}
				});
			}
		});	
	}
};


Ext.milan.pagejs.page_modulemanage.addSubModules = function(formId) {
	var formEle = $(formId);
	if((Ext.milan.pagejs.page_modulemanage.selectCount(formEle)== 0))
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择要添加的功能！");
		return false;
	}
	else
	{
		formEle.action = "module/saveSubs.do";
		new Milan.widget.ConfirmDialog("确认信息", "确认要添加该功能吗？", {
			confirmCallback: function() {
				Milan.ajaxutility.formSubmit({
					form : formEle.id,
					method: 'post',
					success: function(response, option)
					{
						Ext.milan.pagejs.page_modulemanage.closeWin();
						Ext.milan.pagejs.page_modulemanage.refreshTree($('appid').value);
					}
				});
			}
		});	
	}
};

Ext.milan.pagejs.page_modulemanage.modifySubType = function(formId)
{
	var formEle = $(formId);
	if(Ext.milan.pagejs.page_modulemanage.selectCount(formEle)!= 1)
	{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择一个功能！");
		return false;
	}
	else
	{
		var typeId ;
		var types = formEle.selectCheck;
		if(types)
		{
			if(types.length){
				for (i = 0; i < types.length; i++) 
				{
					if (types[i].checked) 
					{
						typeId = types[i].value
					}
				}
			}
			else{
				
				if (types.checked) 
				{
					typeId = types.value
				}
			}
		}
	}
    var url = "module/edit.do?mdid="+typeId;
	Ext.milan.pagejs.page_modulemanage.userWin = Milan.commonutils.createModelPop({
		title:"编辑", 
		url:url,
		width:650
	});
}



/**
 * 保存新建用户信息
 */
Ext.milan.pagejs.page_modulemanage.save = function(formId) {
	Ext.milan.pagejs.page_modulemanage._saveInfo(formId);
};

/**
 * 保存编辑后的信息
 */
Ext.milan.pagejs.page_modulemanage.edit = function(formId) {
	Ext.milan.pagejs.page_modulemanage._saveInfo(formId);
};

/**
 * 关闭弹出窗口
 */
Ext.milan.pagejs.page_modulemanage.closeWin = function(winName) {
	if(winName){
		if(winName=='inactivateConsignerWin')
			inactivateConsignerWin.closeDialog();
	}
	else
		Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_modulemanage.userWin);
};

Ext.milan.pagejs.page_modulemanage.refreshTree = function(appid)
{
	Milan.ajaxutility.formSubmit(
	{
		url : "module/tree.do?appid="+appid,
		success : function(response,option)
		{
			Milan.ajaxutility.updateContainer("module_left_data",response.responseText);
			/*
			if ($("knowledgeListFormId")) 
			{
				Ext.milan.pagejs.page_knowledgelist.refreshTree(showId);
			}
			if($("dirManagerKnowledgeTypeListFormId"))
			{
				Ext.milan.pagejs.page_dirmanagerknowledgetypelist.refreshTree(showId,true)
			}
			*/
		},
		displayMasker:false,
		displayLoading:false
	});
}

Ext.milan.pagejs.page_modulemanage.chkAllClick = function(chkObj)
{
	var formEle = chkObj.form;
	var ch=false;
	var i=0;
	if (chkObj.checked) ch=true;
	
	var selects = formEle.selectCheck;
	var selCount=0;
	if (selects!=null)
	{
		if (selects.length!=null) //有两条以上的记录
		{	
			for (i=0;i<selects.length;i++)
			{
				selects[i].checked=ch;
				Ext.milan.pagejs.page_modulemanage.chkClick(selects[i]);
			}
		}
	  	else
		{
			selects.checked=ch;
			Ext.milan.pagejs.page_modulemanage.chkClick(selects);
		}
	}
}

Ext.milan.pagejs.page_modulemanage.selectCount = function(formEle)
{
	var types = formEle.selectCheck;
	var selCount=0;
	if (types!=null)
	{
		if (types.length!= null) 
		{
			for (i = 0; i < types.length; i++) 
			{
				if (types[i].checked) 
				{
					selCount++;
				}
			}
		}
		else 
		{
			if (types.checked) 
				selCount++;
		}
	}
	return selCount;
}
Ext.milan.pagejs.page_modulemanage.backAppsList = function()
{
	url = "pubApps/list.do";
	Milan.pagejs.page_index.updateCurrentTabByUrl(url);
}
